package org.liquidByte.trafficMustang.androidApp.activities;

import org.liquidByte.trafficMustang.R;
import org.liquidByte.trafficMustang.androidApp.Config;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;

public class ConfigurationActivity extends Activity implements OnClickListener {
	private EditText edtContextRoot;
	private ImageButton imgbCancelar;
	private ImageButton imgbConfirmar;
	
	protected EditText getEdtContextRoot() {
		if (this.edtContextRoot == null) {
			this.edtContextRoot = (EditText)this.findViewById(R.id.activity_configuration_edtContextRoot);
		}
		return edtContextRoot;
	}
	protected ImageButton getImgbCancelar() {
		if (this.imgbCancelar == null) {
			this.imgbCancelar = (ImageButton)this.findViewById(R.id.activity_configuration_imgbCancelar);
		}
		return imgbCancelar;
	}
	protected ImageButton getImgbConfirmar() {
		if (this.imgbConfirmar == null) {
			this.imgbConfirmar = (ImageButton)this.findViewById(R.id.activity_configuration_imgbConfirmar);
		}
		return imgbConfirmar;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_configuration);
		
		this.getImgbCancelar().setOnClickListener(this);
		this.getImgbConfirmar().setOnClickListener(this);
		
		this.getEdtContextRoot().setText(Config.getInstance().getContextRoot());
	}

	@Override
	public void onClick(View view) {
		if (this.getImgbCancelar() == view) {
			this.finish();
		} else if (this.getImgbConfirmar() == view) {
			Config.getInstance().setContextRoot(this.getEdtContextRoot().getText().toString());
			this.finish();
		}
	}
}
